<!-- #section:basics/content.breadcrumbs -->
<link rel="stylesheet" type="text/css"
      href="$request.contextPath/res/framework/datetimepicker/jquery.datetimepicker.css"/>

<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try {
            ace.settings.check('breadcrumbs', 'fixed')
        } catch (e) {
        }
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="#">管理后台</a>
        </li>
        <li class="active">发奖管理</li>
    </ul>

</div>

<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
        <!-- /.page-header -->
        <div class="row">
            <div class="col-xs-12">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>UID</th>
                        <th>物品</th>
                        <th>游戏Id</th>
                        <th>申请时间</th>
                        <th>姓名</th>
                        <th>电话</th>
                        <th>Email</th>
                        <th>地址</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="user_list"></tbody>
                </table>
            </div>
            <!-- /.span -->
        </div>
        <div id="biuuu_city" style="margin: 5px;text-align: center"></div>

    <!-- /.row -->
</div>
<!-- /.page-content -->
<div id="modal-category" class="modal fade" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">×</span>
                    </button>
                    修改领奖状态
                </div>
            </div>
            <form class="form-horizontal" method="post" role="form" id="submitForm" action="./reward/save" enctype="multipart/form-data" novalidate="novalidate">
                <input type="hidden" name="rewardId" id="rewardId" value="0">
                <div class="modal-body no-padding">
                    <div class="space-4"></div>

                    <div class="form-group">
                        <label class="col-sm-2 col-xs-12 control-label no-padding-right"> 广告位 </label>
                        <div class="col-sm-9  col-xs-12 ">
                            <select name="stats" class="form-control" id="stats">
                                <option value="">选择发货状态</option>
                                <option value="0">待处理</option>
                                <option value="1">已发货</option>
                                <option value="2">已拒绝</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="modal-footer no-margin-top text-right">
                    <button class="btn btn-sm btn-success " type="submit">
                        <i class="ace-icon fa fa-check"></i>
                        提交
                    </button>
                    <!--&nbsp;&nbsp;-->
                    <!--<button class="btn btn-sm btn-default " data-dismiss="modal">-->
                    <!--<i class="ace-icon fa fa-times"></i>-->
                    <!--关闭-->
                    <!--</button>-->
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!--<script type="text/javascript" src="$request.contextPath/res/assets/js/ace/elements.fileinput.js"></script>-->
<script src="$request.contextPath/res/framework/datetimepicker/jquery.datetimepicker.js"></script>
<script type="text/javascript">
    var submitLock = false;
    var validator;
    //    var productId = '$productId';

    var options = {
        beforeSerialize:function() {
        },
        beforeSubmit: function () {
            if (submitLock) {
                return false;
            }
            info('正在保存，请稍等...');
            submitLock = true;
            return true;
        },
        success: function (data) {
            submitLock = false;
            console.log(data);
            if (data.resultCode == 0) {
                succ('操作成功');
                $('#modal-category').modal('toggle');
                delay(function () {
                    //$('#modal-category').modal('hide');
                    getPageData(1);
                }, 1000);
            } else {
                error(data.resultMsg);
            }
        },
        error: function (data) {
            submitLock = false;
            error('系统繁忙，请稍候重试');
        },
        dataType: 'json',
        type: 'POST',
        timeout: 50000
    };
    $(function () {
        validator = $("#submitForm").validate({
            errorElement: "em",
            errorPlacement: function (error, element) {
                element.after(error);
            },
            rules: {
                "file": {
                    required: true
                }
            },
            messages: {
                "file": {
                    required: '请选择图片'
                }
            },
            submitHandler: function (form) {
                if (submitLock) {
                    return;
                }
                $(form).ajaxSubmit(options);
            }
        });
    });

    function showEditDialog(rewardId) {
        $('#submitForm').clearForm();
        $('#submitForm').find('#rewardId').val(rewardId);
        $('#modal-category').modal('show');
    }

    $(document).ready(function() {
        getPageData(1);
    });

    function doQuery() {
        getPageData(1);
    }

    function getPageData(curr){
        var brands;
        $.ajax({
            url: "./zzl/exchanges",
            type: "GET",
            dataType: 'json',
            data: {
                "pgNum" : curr,
                "pgSize" : 20,
            },

            success: function (data) {
                brands = data.data["list"];
                //console.log(data.list);
                //调用分页
                laypage({
                    cont: 'biuuu_city',
                    pages: data.data['pages'],
                    curr: curr, //当前页
                    jump: function(obj, first){ //触发分页后的回调
                        if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                            getPageData(obj.curr);
                        }
                    }
                })
                /*<th>UID</th>
                <th>物品</th>
                <th>游戏Id</th>
                <th>申请时间</th>
                <th>姓名</th>
                <th>电话</th>
                <th>Email</th>
                <th>地址</th>
                <th>状态</th>*/
                var str = "";
                for(var i in brands){
                    var kys = brands[i];
                    str += "<tr>";
                    str += "<td >" + kys['uid'] + "</td>";
                    str += "<td >" + kys['itemId'] + "</td>";
                    str += "<td >" + kys['gameId'] + "</td>";
                    str += "<td >" + kys['insertTime'] + "</td>";
                    str += "<td >" + kys['name'] + "</td>";
                    str += "<td >" + kys['phone'] + "</td>";
                    str += "<td >" + kys['email'] + "</td>";
                    str += "<td >" + kys['address'] + "</td>";
                    str += "<td >" + kys['stats'] + "</td>";
                    str += "<td >"
                    str += "<div class=\"action-buttons\">"
                            +"<a class=\"green\" href=\"#\""
                            +" onclick=\"showEditDialog('"+kys['rewardId'] +"')\" "
                            +"title=\"编辑\""
                            +"hideFocus=\"true\">"
                            +"<i class=\"ace-icon fa fa-pencil bigger-130\" hideFocus=\"true\"></i>"
                            +"</a>";
                    str += "</td>";
                    str += "</tr>";
                }
                //console.log(str);
                $("#user_list").html(str);
            },
            error:function(data){
                layer.msg('获取记录失败！', {icon: 5});
            }
        });
    }
</script>